//
//  PPResetPasswordViewController.m
//  pet
//
//  Created by 陈无忌 on 1/9/15.
//  Copyright (c) 2015 whalefin. All rights reserved.
//

#import "PPResetPasswordViewController.h"
#import "supportingHeadFiles.h"

@interface PPResetPasswordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *setPasswordTextField;
@property (weak, nonatomic) IBOutlet UITextField *checkTextField;

@end

@implementation PPResetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.setPasswordTextField.delegate = self;
    self.checkTextField.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [self.setPasswordTextField resignFirstResponder];
    [self.checkTextField resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)confirm:(id)sender {
    [self.setPasswordTextField resignFirstResponder];
    [self.checkTextField resignFirstResponder];
    if (self.setPasswordTextField.text.length > 5) {
        if ([self.setPasswordTextField.text isEqualToString:self.checkTextField.text]) {
            NSString *url = [PPAPIList getAPIList].PPChangePasswordWithoutLogin;
            NSDictionary *params = @{@"phoneNum":self.phoneNum,@"newPassword":self.setPasswordTextField.text};
            [httpRequst POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSString *msg = responseObject[@"errorMsg"];
                NSNumber *result = responseObject[@"processResult"];
                if (result.boolValue) {
                    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
                }else{
                    [PPHUD hudShowWithString:msg andView:self.view];
                }
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                [PPHUD hudShowWithString:@"网络不给力" andView:self.view];
            }];
        }else{
           [PPHUD hudShowWithString:@"2次密码输入不一致，请重试" andView:self.view];
        }
    }else{
        [PPHUD hudShowWithString:@"请输入长度不少于6位的密码" andView:self.view];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (![self.setPasswordTextField isExclusiveTouch]) {
        [self.setPasswordTextField resignFirstResponder];
    }
    if (![self.checkTextField isExclusiveTouch]) {
        [self.checkTextField resignFirstResponder];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
